<?php
	session_start();
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/OrderService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Context/BaseContext.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/ServiceResult/ServiceResult.php';
    $orderService = new OrdersService();
   
	if(isset($_POST['dateFrom']) && isset($_POST['dateTo']) && isset($_POST['consignee']))
	{
		$context = new BaseContext();
		$result = new ServiceResult();
		$dateFrom = $_POST['dateFrom'];
		$dateTo = $_POST['dateTo'];
		$consignee = $_POST['consignee'];
		$orderDomainArr = $orderService->findAllByConsigneeAndOrderDate($context, $result, $consignee, $dateFrom, $dateTo);
		$totalAmountUSD = 0;
		$totalAmountEUR = 0;
		foreach ($orderDomainArr as $orderDomain)
		{
			$totalAmountUSD = $totalAmountUSD + $orderDomain->getSumUSD();
			$totalAmountEUR = $totalAmountEUR + $orderDomain->getSumEUR();
		}
		
	}
?>
<table>
  <tr>
    <td style="font-size: 14px; font-weight: bold; padding-top: 10px;">Turnover Summary:</td>
  </tr>
  <tr>
    <td><?php echo '<font color="red" style="padding:15px; font-size: 12px;">+ Total Amount USD:</font><font style="padding:15px; font-size: 12px; font-weight:bold;">$' .Tool::convertNumberToMoney($totalAmountUSD).'</font>';?></td>
  </tr>
  <tr>
    <td><?php echo '<font color="red" style="padding:15px; font-size: 12px;">+ Total Amount EUR:</font><font style="padding:15px; font-size: 12px; font-weight:bold;">&euro;' .Tool::convertNumberToMoney($totalAmountEUR).'</font>';?></td>
  </tr>
</table>
<table id="datatable" style="display: none;">
	<thead>
		<tr>
			<th>Order Number</th>
			<th>SumUSD</th>
			<th>SumEUR</th>
		</tr>
	</thead>
	<tbody>
	<?php 
		
		foreach ($orderDomainArr as $orderDomain)
		{
	?>
		<tr>
			<th><?php echo $orderDomain->getOrderNumber(); ?></th>
			<td><?php echo $orderDomain->getSumUSD(); ?></td>
			<td><?php echo $orderDomain->getSumEUR(); ?></td>
		</tr>
	<?php } ?>
	</tbody>
	<tfoot>
		<tr>
			<td>gaga</td>
		</tr>
	</tfoot>
</table>



	